<template>
	<div class="common">
		<div class="common-top flex flex-align-center">
			<span class="tips">{{modeType=='PRODUCT'?'商品':'原料'}}上架</span>
			<span style="color:#ff0048;border-bottom:1px solid #ff0048;margin-left: 20px;cursor:pointer;" @click.stop="$router.push({path:'/Bar_Inner',query:{queryModeType:modeType}})">搜索{{modeType=='PRODUCT'?'商品':'原料'}}模式上架</span>
			<!-- <div class="search-box" style="z-index:999">
				<el-input
				 	class="input-box"
				    placeholder="请输入名称"
				    prefix-icon="el-icon-search"
				    v-model="keyWords"
				    @blur="blurSearch"
					>
				</el-input>
				<ul class="ul-box" v-if="searchArr.length">
					<li v-for="item in searchArr" v-text="item.name" @click="getSearchItem(item)"></li>
				</ul>
			</div> -->
			<div class="change-stock-btn mode">
				<span>商品</span>
				<span :class="modeType=='PRODUCT'?'change-btn':'change-btn right-btn'" @click.stop="changeModeType">
					<i @click.stop=""></i>
				</span>
				<span>原料</span>
			</div>
			<!-- <div class="search-btn" style="margin-left:80px;" @click="getBatchData">
				全部商品
			</div> -->
		</div>
		<div class="content-box">
			<div class="content" v-if="modeType=='PRODUCT'">
				<div class="titleTable">
					<table>
	                    <tr>
	                        <th style="width: 8%">序号</th>
	                        <th style="width:10%">分类名</th>
	                        <th style="width:12%">商品名称</th>
	                        <th style="width:12%">现有库存</th>
	                        <th style="width:12%">请输入上架数量(个)</th>
	                        <!-- <th style="width:12%">吧台原有件数(件)</th> -->
	                        <!-- <th style="width:10%">规格(个/件)</th> -->
	                        <!-- <th style="width:12%">每件进价(元/件)</th> -->
	                        <!-- <th style="width:10%">上架件数(件)</th> -->
	                        <!-- <th style="width:12%">操作</th> -->
	                    </tr>
	                </table>
				</div>
                <div class="scrollBox">
                    <div class="scroll">
                        <table class="conTable">
                            <tr v-for="(item,ind) in homeArr">
                                <td style="width:8%" v-text="ind+1"></td>
                                <td style="width:10%" v-text="item.typeName"></td>
                                <td style="width:12%" v-text="item.name" :title="item.name"></td>
                                <td style="width:12%" v-text="item.quantity"></td>
								<td style="width:12%">
                                	<span class="table-input"><input type="text" maxlength="5" v-model="item.single" onfocus="this.select()"></span>
                                </td>
                                <!-- <td style="width:12%" v-text="item.stockQuantityRatio==0?'-':parseInt(item.counterQuantity/item.stockQuantityRatio)"></td> -->
                                <!-- <td style="width:12%" v-text="stockInData.stockQuantityRatio==0?stockInData.counterQuantity:(stockInData.counterQuantity%stockInData.stockQuantityRatio)"></td> -->
                                <!-- <td style="width:10%">
                                	<span v-if="item.isStock" class="table-input">
										<input type="text" maxlength="4" v-model="item.stockQuantityRatio" @keyup.enter="modify(item,ind,'stock')">
										<span @click="modify(item,ind,'stock')" class="sure-btn">确定</span>
									</span>
									<span v-else><span v-text="item.stockQuantityRatio"></span></span>
                                </td> -->
                                <!-- <td style="width:12%">
                                	<span v-if="item.isPrice" class="table-input">
	                                	<input type="text" maxlength="8" v-model="item.stockPrice" @keyup.enter="modify(item,ind,'price')" class="inputPrice">
	                                	<span @click="modify(item,ind,'price')" class="sure-btn">确定</span>
                                	</span>
									<span v-else><span v-text="item.stockPrice"></span><i class="iconfont icon-bianji" @click="homeArr[ind].isPrice=true"></i></span>
                                </td> -->
                                <!-- <td style="width:10%">
                                	<span class="table-input"><input type="text" maxlength="4" v-model="item.whole" onfocus="this.select()"></span>
                                </td> -->
                                
                                <!-- <td style="width:12%">
                                	<span class="btn" @click="del(item,ind)">删除</span>
                                </td> -->
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="content-footer clearfix">
				    <div class="right flex flex-align-center" style="height:100%;">
				    	<div class="footer-btn sure" @click="willUp">
							下一步
				    	</div>
				    </div>
                </div>
			</div>
			<div class="content" v-if="modeType=='MATERIAL'">
				<div class="titleTable">
					<table>
	                    <tr>
	                        <th style="width: 8%">序号</th>
	                        <th style="width:12%">原料名称</th>
	                        <th style="width:12%">现有数量</th>
	                        <th style="width:12%">请输入上架数量</th>
	                        <!-- <th style="width:12%">操作</th> -->
	                    </tr>
	                </table>
				</div>
                <div class="scrollBox">
                    <div class="scroll">
                        <table class="conTable">
                            <tr v-for="(item,ind) in homeArr">
                                <td style="width:8%" v-text="ind+1"></td>
                                <td style="width:12%" v-text="item.name" :title="item.name"></td>
                                <td style="width:12%" v-text="item.stockQty"></td>
								<td style="width:12%">
                                	<span class="table-input"><input type="text" maxlength="5" v-model="item.single" onfocus="this.select()"></span>
                                </td>
                                
                                <!-- <td style="width:12%">
                                	<span class="btn" @click="del(item,ind)">删除</span>
                                </td> -->
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="content-footer clearfix">
				    <div class="right flex flex-align-center" style="height:100%;">
				    	<div class="footer-btn sure" @click="willUp">
							下一步
				    	</div>
				    </div>
                </div>
			</div>
		</div>

		<div class="dialog-box" v-if="dialogBtn" @click="dialogBtn=false">
			<div class="dialog position-middle-center" @click.stop="">
				<span class="close-btn" @click="dialogBtn=false"><i class="iconfont icon-close-b"></i></span>
				<div class="dialog-title">确认上架</div>
				<div class="dialog-content" style="margin-top:20px;">
					<div class="dialog-content-item-center">
						<span>上架商品总共<span class="big-num" v-text="billData.kind">  </span>种</span>
					</div>
					<!-- <div class="dialog-content-item clearfix select-box">
						<span>总额</span>
						<el-input
						 	class="input-box"
						    placeholder="本次上架的总金额"
						    v-model="billData.totalAmount">
						  </el-input>
					</div> -->
					<!-- <div class="dialog-content-item clearfix select-box">
						<span>原因</span>
						<el-select v-model="billData.typeValue" placeholder="请选择上架原因" class="select">
						    <el-option
						      v-for="item in typeOptions"
						      :key="item.value"
						      :label="item.label"
						      :value="item.value">
						    </el-option>
						</el-select>
					</div> -->
					<div class="dialog-content-item clearfix select-box">
						<span>备注</span>
						<el-input
						 	class="input-box"
						    placeholder="如有需求，请填写备注"
						    v-model="billData.notes">
						</el-input>
					</div>
					<!-- <div class="dialog-content-item clearfix imgfile-box">
						<span class="left">单据</span>
						<div class="img left">
							<img :src="billData.imgUrl" alt="">
							<input type="file" accept=".png,.jpg,.jpeg" @change="coverImg($event)" class="pcImgFile" title="选择图片">
						</div>
						<div class="left right-notes">
							<p>支持JPG、JPEG、PNG格式单张大小不超过5M</p>
							<p class="status" v-if="billData.imgUrl">上传成功</p>
						</div>
					</div> -->
					<!-- <div class="dialog-content-item clearfix dialog-content-print">
						<span>打印</span>
						<input type="checkbox" class="isPrint" v-model="billData.isPrint">
						<input type="text" class="printNum" v-model="billData.printNum"  v-if="billData.isPrint">	
					</div> -->
				</div>
				<div class="dialog-footer">
					<div class="footer-btn cancle" @click="dialogBtn=false">取消</div>
					<div class="footer-btn sure" @click="stockUp">确定</div>
				</div>
			</div>
		</div>
		<div style="display:none;">
			<div id="print">
				<h1 style="text-align:center;font-size:18px;">欢迎使用火星捕手</h1>
				<p style="text-align:center;font-size:16px;">吧台上架小票</p>
		    	<div>
		    		<span>店铺名:</span>
		    		<span v-text="store.storeName"></span>
		    	</div>
		    	<div>
		    		<span>操作员:</span>
		    		<span v-text="store.employeeName"></span>
		    	</div>
				<div>
		    		<span>打印时间:</span>
		    		<span>{{new Date() | numberToAllDate('')}}</span>
		    	</div>
		    	<div>
		    		<span>总金额:</span>
		    		<span v-text="billData.totalAmount"></span>
		    	</div>
		    	<div>
		    		<span>上架原因:</span>
		    		<span v-text="sourceType[billData.typeValue]"></span>
		    	</div>
		    	<div>
		    		<span>备注:</span>
		    		<span v-text="billData.notes"></span>
		    	</div>
		    	<div v-for="(item,idx) in homeArr" style="margin-top:10px;border:1px solid #444">
		    		<table style="width:100%;border-collapse: collapse;table-layout:fixed;font-size:12px;">
	    				<tr>
	    					<td style="width:50%;overflow:hidden;white-space:nowrap;" >
	    						<span>名称:</span>
	    						<span v-text="item.name"></span>
	    					</td>
	    					<td style="width:50%;" >
	    						<span>规格(个/件):</span>
	    						<span v-text="item.stockQuantityRatio"></span>
	    					</td>
	    				</tr>
	    				<tr>
	    					<td style="width:50%;" >
	    						<span>上架件数:</span>
	    						<span v-text="item.whole"></span>
	    					</td>
	    					<td style="width:50%;" >
	    						<span>上架个数:</span>
	    						<span v-text="item.single"></span>
	    					</td>
	    				</tr>
		    		</table>
		    	</div>
			</div>
		</div>
		<img-crop v-if="showCrop" :oldImg="oldImgBase64" :curCropW="curCropW" :curCropH="curCropH" :storeId="storeId" @closeImgCrop="showCrop=false" @getCropImgBase="getCropImgBase"></img-crop>
					
	</div>
</template>
<script>
import imgCrop from '@/components/imgCrop/imgCrop.vue';
import {API_BASE_URL} from "./../../../urlConfig/index";
export default {
	components: {imgCrop},
  	props:['storeId','store'],
  	data(){
		return {
      		modeType:"PRODUCT",
			typeOptions: [
				{value: 'ALLOCATION_IN',label: '店铺调拨'},
				{value: 'PURCHASE_IN',label: '采购上架'}
		    ],
		    sourceType:{
				PURCHASE:'采购上架',
				ALLOCATION_IN:'店铺调拨',
				CHECK_IN:'盘点上架',
				STOCK_OUT_ONE:'吧台到仓库',
				CHECK_OUT:'盘点出库',
				STORAGE:'仓储（仓库至吧台）',
				REFUND:'退单上架',
				SALES:'销售出库',
				REFUND_OUT:'退货出库',
				DECLINE:'吧台下架'
			},
	        keyWords:'',
	        currentPage: 1,
	        pageSize:10,
	        total:516,
	        dialogBtn:false,
	        options:[],
	        typeId:'',

	       	coverImgMaxSize: 5*1024*1024, // 图片最大字节数
            oldImgBase64: '', // 原图base64
            showCrop: false, // 控制图片裁剪显示隐藏
            curCropW: 600, // 裁剪宽度
            curCropH: 600, // 裁剪高度

	        searchArr:[],//搜索的商品列表
	        homeArr:[],//首页商品列表
	        billData:{
	        	typeValue: '',
	        	notes:'',
	        	totalAmount:0,//用户手动输入的总金额
	        	imgUrl:'',
	        	kind:0,
	        	printNum:1
	        },
			preventBtn:true,
			searchItem:{},//所点击的搜索结果列表对象
			stockInData:null
		}
	},
	watch:{
	    keyWords(val){
		   	this.searchArr = [];
		   	if(!val){
		   		return;
		   	}
		   	// 搜索
			if(this.modeType == "MATERIAL"){
				this.$http({
				url: "query/list",
				method: "GET",
				params: {
					storeId: this.storeId,
					name: val
				}
				}).then(res => {
					this.searchArr = res.data;
				});
			}else{
				this.$http({
				url: "search",
				method: "GET",
				params: {
					storeId: this.storeId,
					q: val
				}
				}).then(res => {
					this.searchArr = res.data;
				});
			}
	   }
	},
	methods:{
		getGoodsData(){
			this.$http({
			url: "type/stock",
			method: "GET",
			params: {
				storeId: this.storeId,
				mold:this.modeType,
				page:0,
				size: 10000,
			}
		}).then(res => {
			this.homeArr = res.data.content;
		})
		},
		changeModeType(){
			this.homeArr = [];
			this.modeType == "PRODUCT"?this.modeType="MATERIAL":this.modeType="PRODUCT";
			this.getGoodsData();
		},
		blurSearch(){
	    	setTimeout(()=>{
	    		this.searchArr = [];
	    	},800)
	    },
		 //获取批量数据
	    getBatchData(){
	    	if ( !this.preventBtn ) {
                return;
            }
            this.preventBtn = false;
	    	this.homeArr = [];
	    	this.$http.get(this.storeId+'/homePage?page=0&size=10000').then((res)=>{
	    		let data = res.data.products
	    		for (var i = 0; i < data.length; i++) {
	    			let obj = {
	    				isStock:false,//规格是否处于修改状态
	    				isPrice:false,//价格是否处于修改状态
	    				whole: 0,
	    				single: 0,
	    				id:data[i].id,
	    				name:data[i].name,
	    				counterQuantity:data[i].counterQuantity,//吧台数量
	    				stockPrice:data[i].stockPrice/100,//每件价格
	    				stockQuantityRatio:data[i].stockQuantityRatio,//规格
	    				typeName:data[i].typeName,//分类
	    				warehouseQuantity:data[i].warehouseQuantity//仓库库存
	    			};
	    			this.homeArr.push(obj);
	    		}
	    		setTimeout(()=>{
	    			this.preventBtn = true;
	    		},500)
	    	}).catch((err)=>{
				setTimeout(()=>{
	    			this.preventBtn = true;
	    		},500)
	    	})
	    },
		 //警告修改规格
	    willModify(ind){
	        this.homeArr[ind].isStock=true;
	    },
		 //修改规格 和 价格
	    modify(item,ind,boo){
	    	if(boo=='stock'){
	    		//修改规格
	    		if(!/^[1-9]\d*$/.test(item.stockQuantityRatio)){
                    this.$message({
                    	showClose: true,
                        message: item.name+' 规格有误',
                        type: 'error'
                    })
                    return true;
                }
                this.$alert('商品规格修改为：'+item.stockQuantityRatio+'，建议新建商品！', '确认修改',  {
		         	confirmButtonText: '提交',
		          	// cancelButtonText: '去修改',
		          	// type: 'error'
		        }).then(() => {
		    		this.$http.post('/modify-format',{productId:item.id,stockQuantityRatio:parseInt(item.stockQuantityRatio)}).then((res)=>{
		    			this.homeArr[ind].isStock = false;
		    			this.$message({
		    				showClose: true,
				            message: '修改成功',
				            type: 'success'
				        })
		    		})
		        }).catch(() => {
		        	this.homeArr[ind].isStock=false;
		        });
	    	}else if(boo=='price'){
	    		//修改价格
	    		if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(item.stockPrice)){
                    this.$message({
                    	showClose: true,
                        message: item.name+' 每件价格有误',
                        type: 'error'
                    })
                    return true;
                }
	    		this.$http.post('/modify-stock-price',{productId:item.id,stockPrice:parseFloat(item.stockPrice)}).then((res)=>{
	    			this.homeArr[ind].isPrice = false;
	    			this.$message({
	    				showClose: true,
			            message: '修改成功',
			            type: 'success'
			        })
	    		})
	    	}
	    },
		//删除某个商品
		del(item,ind){
			this.$confirm(`是否确认 ${item.name} 不上架`, '是否上架', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(()=>{
				this.homeArr.splice(ind ,1);
			});
		},
		//根据id获取某个商品
	    getSearchItem(item){
			this.searchItem = item;
	    	for (var i = 0; i < this.homeArr.length; i++) {
	    		if(this.homeArr[i].id==item.id){
		    		this.$message({
		    			showClose: true,
			            message: '请勿重复添加',
			            type: 'error'
			        })
			        return;
	    		}
	    	};
	    	// this.$http.get(this.storeId+'/stock/product-search?productId='+item.id).then((res)=>{
	    	// 	this.keyWords = '';
	    	// 	let obj = {
	    	// 		isStock:false,//规格是否处于修改状态
    		// 		isPrice:false,//价格是否处于修改状态
	    	// 		id:res.data.id,
	    	// 		name:res.data.name,
	    	// 		whole: 0,
	    	// 		single: 0,
	    	// 		stockPrice:res.data.stockPrice/100,
	    	// 		typeName:res.data.typeName,
	    	// 		stockQuantityRatio:res.data.stockQuantityRatio,
	    	// 		warehouseQuantity:res.data.warehouseQuantity,
	    	// 		counterQuantity:res.data.counterQuantity,
	    	// 	};
	    	// 	this.homeArr.push(obj);
			// })
			if(this.modeType == "PRODUCT"){
				this.getProduct(item);
			}else{
				this.getMaterial(item);
			}
			
	    },
		getMaterial(item){
			let store = JSON.parse(sessionStorage.getItem('store'));
			this.$http({
				url:'detail',
				method:'GET',
				params:{
					id: item.id,
				}
			}).then(res=>{
				console.log(res);
				res.data.quantity = res.data.stockQty;
	    		this.keyWords = '';
				this.stockInData = res.data;
				this.stockInData.single = 0;
				this.homeArr.push(this.stockInData);
			});
		},
		getProduct(item){
			let store = JSON.parse(sessionStorage.getItem('store'));
			this.$http({
				url:'get-product',
				method:'GET',
				params:{
					productId:item.id,
					storeId:this.storeId,
					empId:store.employeeId
				}
			}).then(res=>{
				console.log(res);
	    		this.keyWords = '';
				this.stockInData = res.data;
				this.stockInData.single = 0;
				this.homeArr.push(this.stockInData);
			});
		},
	    willUp(){
			let kind = 0;
	    	// if(this.homeArr.length==0){
	    	// 	this.$message({
	    	// 		showClose: true,
		    //         message: '请选择商品',
		    //         type: 'error'
		    //     })
		    //     return;
	    	// }else{
	    	// 	for (var i = 0; i < this.homeArr.length; i++) {
		    // 		if(!/^\d+$/.test(this.homeArr[i].whole)){
			//     		this.$message({
			//     			showClose: true,
			// 	            message: '请输入正确的  '+this.homeArr[i].name+'  商品件数',
			// 	            type: 'error'
			// 	        })
			// 	        return;
		    // 		}
		    // 		if(!/^\d+$/.test(this.homeArr[i].single)){
			//     		this.$message({
			//     			showClose: true,
			// 	            message: '请输入正确的  '+this.homeArr[i].name+'  商品个数',
			// 	            type: 'error'
			// 	        })
			// 	        return;
		    // 		}
		    // 	};
	    	// }
	    	// this.dialogBtn=true;
			// this.billData={typeValue: '',notes:'',totalAmount:0,imgUrl:'',printNum:1,isPrint:false,kind:this.homeArr.length}
			if(this.homeArr.length==0){
	    		this.$message({
	    			showClose: true,
		            message: '请选择商品',
		            type: 'error'
		        })
		        return;
	    	}else{
	    		for (var i = 0; i < this.homeArr.length; i++) {
		    		// if(!/^\d+$/.test(this.homeArr[i].whole)){
			    	// 	this.$message({
			    	// 		showClose: true,
				    //         message: '请输入正确的  '+this.homeArr[i].name+'  商品件数',
				    //         type: 'error'
				    //     })
				    //     return;
		    		// }
					if(String(this.homeArr[i].single)!="" && String(this.homeArr[i].single)!="undefined" && String(this.homeArr[i].single)!="null"){
						if(/^0{1,}\d+$/.test(this.homeArr[i].single)){
							this.$message({
								showClose: true,
								message: '请输入正确的  '+this.homeArr[i].name+'  商品数量',
								type: 'error'
							})
							return;
						}
						if(!/^\d+$/.test(this.homeArr[i].single)){
							this.$message({
								showClose: true,
								message: '请输入正确的  '+this.homeArr[i].name+'  商品数量',
								type: 'error'
							})
							return;
						}
						if(this.homeArr[i].single !== 0){
							kind++;
						}else{
							this.$message({
								showClose: true,
								message: this.homeArr[i].name+' 上架数量为0，请检查并修改为大于0的数字',
								type: 'error'
							})
							return;
						}
						if(this.homeArr[i].single == 0){
							this.$message({
								showClose: true,
								message: this.homeArr[i].name+' 上架数量为0，请检查并修改为大于0的数字',
								type: 'error'
							})
							return;
						}
					}
		    	};
			}
			
	    	this.dialogBtn=true;
			this.billData={typeValue: '',notes:'',totalAmount:0,imgUrl:'',printNum:1,isPrint:false,kind}
	    },
	    //提交数据
	    stockUp(){
			console.log(this.homeArr);
    		// if(!/^\d{0,9}$/.test(parseFloat(this.billData.totalAmount)*100)){
            //     this.$message({
            //     	showClose: true,
            //         message: '总金额格式有误',
            //         type: 'error'
            //     })
            //     return;
			// };
			
	    	// if(!this.billData.typeValue){
	    	// 	this.$message({
	    	// 		showClose: true,
		    //         message: '请选择上架原因',
		    //         type: 'error'
		    //     })
		    //     return;
	    	// };
	    	if ( !this.preventBtn ) {
                return;
            }
            this.preventBtn = false;
	    	// let body = {
	    	// 	single:0,
	    	// 	whole:0,
	    	// 	id:this.$uuid(),
	    	// 	storeId:this.storeId,
	    	// 	notes:this.billData.notes,
	    	// 	stockSource:this.billData.typeValue,
	    	// 	totalAmount:parseFloat(this.billData.totalAmount)*100,
	    	// 	bill:this.billData.imgUrl,
	    	// 	source:'COUNTER',
	    	// 	inventores:[]
			// };
			let store = JSON.parse(sessionStorage.getItem('store'))
			let body = {
				// reason:this.billData.typeValue,
				storeId:this.storeId,
				notes:this.billData.notes,
				empId:store.employeeId,
				amount:parseFloat(this.billData.totalAmount),
				skuCount:0,
				operatorName:store.employeeName,
				notes:this.billData.notes,
				code:this.$uuid(),
				barProducts:[],
        		mold:this.modeType
			};
			

	    	// for (var i = 0; i < this.homeArr.length; i++) {
	    	// 	let newInventores = {
	    	// 		productId:this.homeArr[i].id,
	    	// 		productName:this.homeArr[i].name,
	    	// 		single:this.homeArr[i].single,
	    	// 		stockPrice:this.homeArr[i].stockPrice*100,
	    	// 		stockQuantityRatio:this.homeArr[i].stockQuantityRatio,
	    	// 		whole:this.homeArr[i].whole
	    	// 	};
	    	// 	body.whole+=parseInt(this.homeArr[i].whole);
	    	// 	body.single+=parseInt(this.homeArr[i].single);
	    	// 	body.inventores.push(newInventores);
			// }
			for (let i = 0; i < this.homeArr.length; i++) {
				if(this.homeArr[i].single !== 0 && String(this.homeArr[i].single)!="" && String(this.homeArr[i].single)!="undefined" && String(this.homeArr[i].single)!="null"){
					let newInventores = {
						productId:this.homeArr[i].id,
						name:this.homeArr[i].name,
						quantity:this.homeArr[i].single
					};
					body.skuCount+=parseInt(this.homeArr[i].single);
					body.barProducts.push(newInventores);
				}else{
					// this.$message({
					// 	showClose: true,
					// 	message: this.homeArr[i].name+' 上架数量不能为0，如不上架请删除',
					// 	type: 'error'
					// })
					// this.preventBtn = true;
					// return;
				}
	    	}
	    	this.$http.post('/stockIn',body).then((res)=>{
				if(res.data.code === 400){
					this.$message({
						showClose: true,
						message: res.data.msg,
						type: 'error'
					});
	    			this.preventBtn = true;
					return;
				}
	    		this.$message({
	    			showClose: true,
		            message: '操作成功',
		            type: 'success'
		        });
		        // if(this.billData.isPrint){
		        // 	this.$posPrint(this.billData.printNum, document.getElementById("print").innerHTML);
		        // }
		        this.homeArr = [];
				this.getGoodsData();
	    		this.dialogBtn = false;
	    		setTimeout(()=>{
	    			this.preventBtn = true;
	    		},1000)
	    	}).catch((err)=>{
				setTimeout(()=>{
	    			this.preventBtn = true;
	    		},1000)
	    	})
	    },
	    //选择图片
	    coverImg: function ( e ) {
            let reader = new FileReader();
            let that = this;
            let fileObj = e.target.files[0];

            if( e.target.files.length == 0 ) {
                return false;
            }
            // 判断图片大小
            if( fileObj.size > this.coverImgMaxSize ) {
                this.errorMsg = '上传图片的大小不能超过5MB';
                this.openErrorTip = true;
                this.$message({
                	showClose: true,
                    message: '上传图片的大小不能超过5MB',
                    type: 'error'
                })
                return false;
            }
            reader.onload = (function (file) {
                return function (e) {
                    let that2 = this; // 缓存当前this
                    let img = new Image();
                    img.src= this.result;
                    img.onload=function(){
                        let imgBase64 = that2.result; //获得图片的base64的数据

                        // 判断是否是移动端设备
                        let sUserAgent = navigator.userAgent.toLowerCase();
                        let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
                        let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
                        let bIsMidp = sUserAgent.match(/midp/i) == "midp";
                        let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
                        let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
                        let bIsAndroid = sUserAgent.match(/android/i) == "android";
                        let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
                        let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
                        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
                            that.mobileUploadImg(imgBase64);
                        } else {
                            that.oldImgBase64 = imgBase64;
                            that.showCrop = true;
                        }
                    };
                    $('.pcImgFile').val('');
                };
            })(e.target.files[0]);
            reader.readAsDataURL(e.target.files[0]);
        },
        // 移动端上传图片
        mobileUploadImg: function (imgBase64) {
            this.infoload = true;
            this.$http.post(API_BASE_URL+'v1/image/json/upload?storeId='+this.storeId, {file: imgBase64}).then((res)=>{
                this.billData.imgUrl = imgUrl;
                this.infoload = false;
            }).catch(()=>{
                this.infoload = false;
            });
        },
        // 获得裁剪后图片base64
        getCropImgBase: function ( imgUrl )　{
            this.billData.imgUrl = imgUrl;
        }
	},
	created () {
		try {
			if(this.$route.query.queryModeType){
				this.homeArr = [];
				this.modeType = this.$route.query.queryModeType;
			}
		} catch (error) {
		
		}
	},
	mounted() {
		this.getGoodsData();
	},
	beforeDestroy() {

	}
}
</script>
<style lang="scss" scoped>
	@import '../../../../static/css/common.scss';
	@import "inner";
</style>